﻿@using Freesql.Tool.Helpers;
@using Freesql.Tool.Models;
@using System.Collections.Generic;
@{
    var gen = Model as Freesql.Tool.Models.RazorTemplateModel;
    var list = new List<Property>();
    var isEnum = false;
    var classPath = $"{gen.NameSpace}.Domain.Entities.{gen.TableName}";
    list = ReflectionHelper.GetProperties(classPath, false, out isEnum);
    var description = ReflectionHelper.GetDescription(classPath);
    var enums = list.Where(p => p.IsEnum == true).Select(p => p.Name).ToList();
    enums.Add("Values");
    var import = string.Join(",", enums);
    var igron = new string[] { "Id" };
    string GetDesc(string desc)
    {
        if (desc == "CreatTime")
        {
            return "创建时间";
        }
        else if (desc == "UpdateTime")
        {
            return "更新时间";
        }
        return desc;
    }
    string ToLowerFirst(string str)
    {
        return str.Substring(0, 1).ToLower() + str.Substring(1);
    }
}
//https://1x.antdv.com/components/tag-cn/
import { Tag } from 'ant-design-vue';
import type { TableColumn } from '@@/components/core/dynamic-table';
import { formatToDateTime } from '@@/utils/dateUtil';
import { baseApiUrl } from '@@/utils/request';
import { @(import) } from '@@/enums'
export type TableListItem = @(gen.TableName)Out;
export type TableColumnItem = TableColumn<TableListItem>;

export const baseColumns: TableColumnItem[] = [
@foreach (var item in list)
{
    if (igron.Contains(item.Name)) continue;
    if (!item.IsEnum)
    {
        if (!item.Type.StartsWith("bool"))
        {
    @:{ title: '@GetDesc(item.Description)', width: 80, dataIndex: '@ToLowerFirst(item.Name)', hideInSearch: true  },
        }
        else
        {
        @:{
        @:title: '@GetDesc(item.Description)', width: 80, dataIndex: '@ToLowerFirst(item.Name)', hideInSearch: true ,
        @:  customRender: ({ record }) => {
        @:      const isEnable = record.@ToLowerFirst(item.Name);
        @:      return <Tag color={ isEnable ? 'success' : 'red' }>{isEnable ?' 是' : '否' }</Tag>;
        @:  }
        @:},
        }
    }
    else
    {
    @:{
    @:title: '@GetDesc(item.Description)', width: 80, dataIndex: '@ToLowerFirst(item.Name)', hideInSearch: true ,
    @:  customRender: ({ record }) => {
    @:      return <Tag color={ Values.@(item.Name)[record.@ToLowerFirst(item.Name)].color}>{ Values.Gender[record.@ToLowerFirst(item.Name)].desc}</Tag>;
    @:  }
    @:},
    }
}
];
